<?php


namespace DebugBar;


class RequestIdGenerator implements RequestIdGeneratorInterface
{
    protected $index = 0;

    
    public function generate()
    {
        if (function_exists('random_bytes')) {
                        return 'X' . bin2hex(random_bytes(16));
        } else if (function_exists('openssl_random_pseudo_bytes')) {
                        return 'X' . bin2hex(openssl_random_pseudo_bytes(16));
        } else {
                                                                                    $this->index++;
            $entropy = serialize($_SERVER) . uniqid('', true) . spl_object_hash($this) . $this->index;
            return 'X' . md5($entropy);
        }
    }
}
